package strategy;

/**
 * 购买满多少，返回一定惠利
 */
public class CashReturn implements CashStrategy {
    private double moneyCondition = 0d; // 返利条件
    private double moneyReturn = 0d; // 返利值

    public CashReturn(double moneyCondition, double moneyReturn) {
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double price, int num) {
        double result = price * num;
        if(moneyCondition > 0 && result >= moneyCondition) // 达到返利条件时，原价减去返利值
            result = result - Math.floor(result / moneyCondition) * moneyReturn;
        return result;
    }
}
